#pragma once
#include "base/core/script.h"

class ScriptSafeCall 
{
private:
	int operator=(ScriptSafeCall const&);

protected:
	int m_topIndex;
	LuaScript* m_script;

public:
    explicit ScriptSafeCall(LuaScript* sc) : m_script(sc) 
	{
        MMO_ASSERT(sc != nullptr);
        if (sc != nullptr) 
		{
            m_topIndex = sc->GetTopIndex();
        }
    }

    ~ScriptSafeCall() 
	{
        if (m_script != nullptr && m_topIndex >= 0) 
		{
            m_script->SetTopIndex(m_topIndex);
            m_topIndex = -1;
        }
    }

    int GetBeginTopIndex() const 
	{
        return m_topIndex;
    }
};
